package com.huawei.statistics.utils;

import java.util.List;

/**
 * Created by 尹文祥 on 2018\3\22 0022.
 * 分页工具类
 *
 */
public class PageUtil {


    private Integer cur = 0;
    private Integer max = 0;
    private Integer total = 0;//总记录数
    private List dataList = null;//数据集
    private Integer totalPage = 0;//总页数

    public int getCur() {
        return cur;
    }

    public void setCur(int cur) {
        this.cur = cur;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List getDataList() {
        return dataList;
    }

    public void setDataList(List dataList) {
        this.dataList = dataList;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }



    public PageUtil(){}


    public PageUtil(int cur,int max,List list){



            if(list == null){
                this.total = 0;
            }else{
                this.total = list.size();
            }


            this.cur = cur;
            this.max = max;
            if((this.cur-1)*this.max>=this.total){

                this.totalPage = 0;
                this.dataList = null;

            }else {

                this.totalPage = (int) (this.total % max == 0 ? this.total / max : Math.floor(this.total / max) + 1);
                int i = cur == 1?0:(cur-1);


                if(cur == totalPage){

                    this.dataList  = list.subList((cur-1)*max,total);

                }else{
                    this.dataList  = list.subList(i*max,cur*max);


                }

            }


    }

    @Override
    public String toString() {
        return "PageUtil{" +
                "cur=" + cur +
                ", max=" + max +
                ", total=" + total +
                ", dataList=" + dataList +
                ", totalPage=" + totalPage +
                '}';
    }





}
